﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Base.Common;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Base.Entity.Product;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;


namespace T.FAS.Runtime.Base.Dao
{
    public class ProductLineManageInfoDao : DaoService<ProductLine>
    {
        public override string TableName => "t_productline";
        public override string IDColumnName => "ID";
        public ProductLineManageInfoDao() : base()
        {
            //DBName = "TMaster";
            DBName = "TFAS";
        }

        public override List<string> ExceptColumnName => new List<string> { };

        public override ProductLine ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            var myCol = new Dictionary<string, PropertyInfo>(base.Columns);
            var data = base.ConvertToObject(myCol, row);
            return data;
        }

        public List<ProductLine> GetAllProductLineByTenant() {
            List<ProductLine> productLines = new List<ProductLine>();
            List<IDbDataParameter> paramsList = new List<IDbDataParameter>();
            string tenantId = UserUtil.GetCurrentUserTenantId();
            paramsList.Add(this.DB.MakeInParam("@TenantID", TDbDataType.VarChar, tenantId));
            string sql = "select ID,Code,Name,ProductLineLevelID,Description,TenantID,Creator,CreatorName,CreateTime,LastModifier,LastModifierName,LastModifyTime,SortCode from t_productline where TenantID=@TenantID or TenantID is null "; 
            var dataSet = this.DB.ExecuteDataSet(sql, paramsList.ToArray());
            if (dataSet != null && dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    ProductLine productLine = ConvertToObject(this.Columns, row);
                    productLines.Add(productLine);
                }
            }
            return productLines;
        }

        
    }
}
